package com.situ.user.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.situ.user.bean.Shopcart;
import com.situ.user.bean.User;
import com.situ.user.service.ShopcartService;

@Controller
@RequestMapping("/user/cart")
public class CartController {

	@Autowired
	private ShopcartService shopcartService;

	@GetMapping("/add")
	public String add(Integer id, HttpSession session) {
		User user = (User) session.getAttribute("user");
		Shopcart cart = new Shopcart();
		cart.setUserId(user.getId());
		cart.setGoodsId(id);
		cart.setCount(1);// 默认加一个

		shopcartService.add(cart);
		return "redirect:/user/cart";
	}

	@GetMapping
	public String cart() {
		return "user/cart";
	}
}
